{# SPDX-FileCopyrightText: © 2014-2015, 2021 Siemens AG

   SPDX-License-Identifier: FSFAP
#}
{% extends "include/base.html.twig" %}

{% block content %}
    {{ pathOfItem }}

<div class="container">
  <form action='{{ postUrl }}' method='POST'>
    <u><i><b>{{ "Limit search to" | trans }}:</b></i></u>
    <br><br>
    <input type='radio' name='searchtype' value='containers' {{ ContainersChecked }} onclick="setReadonlyForFilters(false);">
    <b>{{ "Containers only (rpms, tars, isos, etc), including directories." | trans }}</b>
    <br><br>
    <input type='radio' name='searchtype' value='directory' {{ DirectoryChecked }} onclick="setReadonlyForFilters(true);">
    <b>{{ "Containers only (rpms, tars, isos, etc), excluding directories." | trans }}</b>
    {{ "The filtering for license or copyright is not supported in this case." | trans }}
    <br><br>
    <input type='radio' name='searchtype' value='allfiles' {{ AllFilesChecked }} onclick="setReadonlyForFilters(false);">
    <b>{{ "All Files" | trans }}</b>
    <br><br>
        <p>
            <u>
                <i>
                    <b>
                        {{ "You must choose one or more search criteria (not case sensitive)." | trans }}
                    </b>
                </i>
            </u>
    <ul>
      <li>
        <div class="form-group">
          <b><label class="control-label col-sm-10">{{ 'Choose upload to search into'|trans }}:</label></b>
          <div class="col-sm-10">
            <select class="form-control" id="scanFilter" name='upload'>
              <option value="0">-- {{ 'All uploads'|trans }} --</option>
              {% for uploadObj in uploadsArray %}
              <option value="{{ uploadObj.getId() }}"> {{ uploadObj.getFilename() }} from {{ uploadObj.getTimestamp() | date("Y-m-d H:i:s") }}</option>
              {% endfor %}
            </select>
          </div>
        </div>
      </li>
      <li>
        <div class="form-group">
          <b><label class="control-label col-sm-10">{{ 'Enter the filename to find'|trans }}:</label></b>
          <div class="col-sm-10">
            <input type="text" class="form-control" name="filename" placeholder="Enter filename" value="{{ Filename|e }}">
          </div>
          <label class="col-sm-10">
            {{ "You can use '%' as a wild-card, For example: '%v3.war', or 'mypkg%.tar'. " | trans }}
          </label>
        </div>
      </li>

      <li>
        <div class="form-group">
          <b><label class="control-label col-sm-2">{{ 'Tag to find'|trans }}:</label></b>
          <div class="col-sm-10">
            <input type="text" class="form-control" name="tag" placeholder="Enter tag to find" value="{{ tag|e }}">
          </div>
        </div>
      </li>

      <li>
        <div class="form-group">
          <b><label class="control-label col-sm-2">{{ 'File size is'|trans }} &ge;</label></b>
          <div class="col-sm-10">
            <input type="text" size=10 class="form-control" name="sizemin" placeholder="Enter file size in bytes" value="{{ SizeMin }}">
          </div>
        </div>
      </li>

      <li>
        <div class="form-group">
          <b><label class="control-label col-sm-2">{{ 'File size is'|trans }} &le;</label></b>
          <div class="col-sm-10">
            <input type="text" size=10 class="form-control" name="sizemax" placeholder="Enter file size in bytes" value="{{ SizeMax }}">
          </div>
        </div>
      </li>

    </ul>
    <p><u><i><b>{{ "You may also choose one or more optional search filters (not case sensitive)." | trans }}</b></i></u></p>
    <ul>

      <li>
        <div class="form-group">
          <b><label class="control-label col-sm-2">{{ 'License'|trans }}:</label></b>
          <div class="col-sm-10">
            <input type="text" class="form-control" name="license" placeholder="Enter license" value="{{ License|e }}">
          </div>
          <label class="col-sm-10">
          {{ "For example, 'AGPL%'." | trans }}
          </label>
        </div>
      </li>

      <li>
        <div class="form-group">
          <b><label class="control-label col-sm-2">{{ 'Copyright'|trans }}:</label></b>
          <div class="col-sm-10">
            <input type="text" class="form-control" name="copyright" placeholder="Enter copyright" value="{{ Copyright|e }}">
          </div>
          <label class="col-sm-10">
          {{ "For example, 'Copyright 2014-2020 fossology'." | trans }}
          </label>
        </div>
      </li>

    </ul>

    <p>
      <div>
        <b><label>Show</label></b>
        <select name="limit">
          <option value="10">10</option>
          <option value="25">25</option>
          <option value="50" selected="selected">50</option>
          <option value="100">100</option>
        </select>
        <b><label>entries</label></b>
      </div>
    </p>

    <input type='hidden' name='item' value='{{ Item }}'>
    <div class="form-group">
      <div class="col-sm-offset-2 col-sm-10">
        <button type="submit" class="btn btn-default">{{ 'Search'|trans }}</button>
      </div>
    </div>
  </form>
</div>

    {{ result }}
{% endblock %}

{% block foot %}
    {{ parent() }}
    <script type="text/javascript">
        function setReadonlyForFilters(isDisabled) {
            function getBackgroundColor() {
                if (isDisabled) return "#ccc";
                else return "#fff";
            }
            $("[name='license']").prop('readonly', isDisabled)
                    .css('background',getBackgroundColor());
            $("[name='copyright']").prop('readonly', isDisabled)
                    .css('background',getBackgroundColor());
        }
        {% if DirectoryChecked is not empty %}
        $( document ).ready(function() {
            setReadonlyForFilters(true);
        });
        {% endif %}

        document.getElementById('scanFilter').value = {{ Upload }};

    </script>
{% endblock %}
